package com.caiyi.financial.nirvana.sms.controller;

import com.caiyi.financial.nirvana.sms.entity.SmsAdmin;
import com.caiyi.financial.nirvana.sms.jedis.JedisKey;
import com.caiyi.financial.nirvana.sms.jedis.JedisService;
import com.caiyi.financial.nirvana.sms.querybean.QueryBatchMsgBean;
import com.caiyi.financial.nirvana.sms.service.SmsBatchMsgService;
import com.youyu.common.api.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api(description = "短信批次管理")
@RestController
@RequestMapping("sms/admin/batchmsg")
public class BatchMsgController {


    @Autowired
    private SmsBatchMsgService BatchMsgService;


    @ApiOperation(value = "根据params查找BatchMsg详情", notes = "根据params查找BatchMsg详情描述")
    @ApiImplicitParam(name = "bean", value = "查找批量短信参数", required = true, dataType = "QueryBatchMsgBean")
    @PostMapping("/getBatchMsgByParams")
    public Result getBatchMsgByParams(@RequestBody QueryBatchMsgBean bean) {
        Subject subject = SecurityUtils.getSubject();
        SmsAdmin user = (SmsAdmin) subject.getPrincipal();
        //获取客户账号是否存在，客户账号只能查询属于自己的短信列表
        String key = String.format(JedisKey.SMS_USER, user.getAccount());
        if (JedisService.exists(key)) {
            bean.setAccount(user.getAccount());
        }
        return Result.ok(BatchMsgService.getBatchMsgByParams(bean));

    }
}
